//
//  FireViewController.m
//  OCAnimation
//
//  Created by zhouLiHuan on 2017/2/17.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

#import "FireViewController.h"

@interface FireViewController ()

@property(nonatomic,strong)CAEmitterLayer *fireEmitter; //发射器对象
@property (nonatomic,strong)UIImageView *candleIV;


@end

@implementation FireViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor blackColor];
    
    self.fireEmitter = [[CAEmitterLayer alloc] init];
    self.candleIV = [[UIImageView alloc] init];
    
    self.fireEmitter.emitterPosition = self.view.center;
    
    //发射器的形状
    self.fireEmitter.emitterShape = kCAEmitterLayerCircle;
    //渲染模式
    self.fireEmitter.renderMode = kCAEmitterLayerAdditive;
    
    //发射单元 - 火焰
    CAEmitterCell *fire = [[CAEmitterCell alloc] init];
    //粒子的创建速度 默认是1/s
    fire.birthRate = 200;
    //粒子的存活时间
    fire.lifetime = 0.2;
    //粒子的生存时间容差
    fire.lifetimeRange = 0.5;
    fire.color = [UIColor colorWithRed:0.8 green:0.4 blue:0.2 alpha:0.1].CGColor;
    fire.contents = (__bridge id _Nullable)([UIImage imageNamed:@"fire.png"].CGImage);
    fire.name = @"fire";
    //粒子的速度
    fire.velocity = 35;
    //粒子动画的速度容差
    fire.velocityRange = 10;
    //粒子的发射角度
    fire.emissionLatitude = M_PI + M_PI_2;
    //粒子发射角度的容差
    fire.emissionRange = M_PI_2;
    
    //缩放速度
    fire.scaleSpeed = 0.3;
    fire.spin = 0.2;
    self.fireEmitter.emitterCells = [NSArray arrayWithObject:fire];
    [self.view.layer addSublayer:self.fireEmitter];
    
 
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 //发射单元 - 火焰
 let fire = CAEmitterCell();
 //粒子的创建速率,默认为1/s
 fire.birthRate = 200;
 //粒子的存活时间
 fire.lifetime = 0.2;
 //粒子的生存时间容差
 fire.lifetimeRange = 0.5;
 fire.color = UIColor.init(colorLiteralRed: 0.8, green: 0.4, blue: 0.2, alpha: 0.1).cgColor;
 fire.contents = UIImage(named:"fire.png")?.cgImage;
 fire.name = "fire";
 //粒子的速度
 fire.velocity = 35;
 //粒子动画的速度容差
 fire.velocityRange = 10;
 //粒子的发射角度
 fire.emissionLongitude = CGFloat(M_PI + M_PI_2);
 //粒子发射角度的容差
 fire.emissionRange = CGFloat(M_PI_2);
 //缩放速度
 fire.scaleSpeed = 0.3;
 fire.spin = 0.2;
 fireEmitter.emitterCells = [fire];
 view.layer.addSublayer(fireEmitter);
 
 }

*/

@end
